<!--
Date: 2025-08-13
Copyright (c) 2025 Industrial Software Feature Database
-->
<template>
  <el-dialog v-if="dialogVisible" v-model="dialogVisible" title="选择对比清单" width="1200px" append-to-body :before-close="closeDialog">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <base-form
            :rule-form-config="ruleFormConfig"
            :rule-form-props="ruleFormProps"
            :rul-form-model="queryParams"
            @handle-query="handleQuery"
            @reset-query="resetQuery"
          >
          </base-form>
        </el-card>
      </div>
    </transition>
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="mb-[10px]">
        <el-card shadow="hover">
          <base-table
            v-loading="tableLoading"
            :table-headers="tableHeaders"
            :table-data="tableData"
            :table-props="tableProps"
            :table-events="tableEvents"
          >
          </base-table>
          <pagination
            v-show="total > 0"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="initData"
          />
        </el-card>
      </div>
    </transition>
    <template #footer>
      <div class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="handleSure">确 定</el-button>
        <el-button @click="closeDialog">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup name="selectListDialog" lang="ts">
import { getTrackList } from '@/api/bomCompareTool/standardInstallationList/index';
// import { getOriginList } from '@/api/bomCompareTool/originInstallationList/index';
const router = useRouter();
const props = defineProps({
  aircraftModel: String,
  bomDetailType: String
});
const queryParams = reactive({
  track: '',
  bomDetailType: props.bomDetailType,
  aircraftModel: props.aircraftModel,
  pageNum: 1,
  pageSize: 10
});
const dialogVisible = ref(false);
const dialogFormRef = ref<ElFormInstance>();
const total = ref(1);
const airModelList = [
  {
    label: 'C919',
    value: 'C919'
  },
  {
    label: 'C929',
    value: 'C929'
  }
];
const ruleFormConfig = reactive([
  {
    prop: 'aircraftModel',
    type: 'BaseSelect',
    formItemProps: {
      label: '机型'
    },
    props: {
      disabled: true,
      clearable: false
    },
    options: airModelList
  },
  {
    prop: 'track',
    type: 'BaseInput',
    formItemProps: {
      label: '批次号'
    },
    props: {
      disabled: false,
      clearable: false
    }
  }
]);
const rulFormModel = reactive({
  aircraftModel: 'C919',
  track: ''
});
const ruleFormProps = reactive({
  inline: true,
  'label-width': '90'
});
const tableLoading = ref(false);
// 表格配置
const tableHeaders = [
  {
    columnProps: {
      type: 'selection',
      width: '35'
    }
  },
  // {
  //   columnProps: { prop: 'originalName', label: '原始文件' }
  // },
  {
    columnProps: { prop: 'track', label: '批次号' }
  },
  {
    columnProps: { prop: 'desc', label: '描述' }
  }
  // {
  // columnProps: { prop: 'aircraftModel', label: '机型', width: '100px' }
  // },
  // {
  //   columnProps: { prop: 'fileType', label: '文件类型', width: '100px' }
  // },
  // {
  //   columnProps: { prop: 'createBy', label: '创建人', width: '100px' }
  // },
  // {
  //   columnProps: { prop: 'createTime', label: '创建时间', width: '180px' }
  // }
];
const tableProps = {
  style: {
    width: '100%'
  }
};
const multipleSelection = ref<Array<any>>([]);
const handleSelectionChange = (val: any[]) => {
  multipleSelection.value = val;
};
const tableEvents = {
  'selection-change': handleSelectionChange
};

// 获取当前实例
const { proxy } = getCurrentInstance();

const showSearch = true;
// 装机清单列表
const initData = async () => {
  tableLoading.value = true;
  const obj = { ...queryParams };
  delete obj.aircraftModel;
  const res = await getTrackList(queryParams.aircraftModel, obj);
  tableData.value = res.rows;
  total.value = res.total;
  tableLoading.value = false;
};
// 搜索
const handleQuery = () => {
  queryParams.pageNum = 1;
  initData();
};
// 重置
const resetQuery = () => {
  queryParams.track = '';
  handleQuery();
};
// 表格数据
const tableData = ref([]);
const buttonLoading = ref(false);
const emit = defineEmits(['on-sure']);
const closeDialog = () => {
  // emit('on-close');
  dialogVisible.value = false;
};
const openDialog = (model) => {
  queryParams.aircraftModel = model;
  dialogVisible.value = true;
  initData();
};
defineExpose({
  openDialog,
  closeDialog
});
const handleSure = () => {
  if (!multipleSelection.value.length) {
    proxy?.$modal.msgWarning('请选择一条数据！');
  } else if (multipleSelection.value.length > 1) {
    proxy?.$modal.msgWarning('请选择一条数据！');
  } else {
    emit('on-sure', multipleSelection.value[0]);
  }
};
onMounted(() => {
  initData();
});
</script>

<style lang="scss" scoped></style>
